﻿using System;
using System.IO;
using YArchitech.LIB;
using YJKCodeBase.XmlUtility;

namespace BuildingOutLine.BuildingOutLine.Forms
{
	public class SettingReaderWriter
	{
		public static void SetSetting(BuildingOutLineSettingInfo setting)
		{
			string workingLocation = Product.WorkingLocation;
			string xmlPath = Path.Combine(workingLocation, "BuildingOutLineSetting.xml");
			YJKCodeBase.XmlUtility.XmlHelper xmlHelper = new YJKCodeBase.XmlUtility.XmlHelper(workingLocation, "Root");
			xmlHelper.SelectNode("Root\\Datas");
			xmlHelper.SetValue("LinePatternName", setting.LinePatternName.ToString());
			xmlHelper.SetValue("LineWidth", setting.LineWidth.ToString());
			xmlHelper.SaveXml(xmlPath);
		}

		public static BuildingOutLineSettingInfo GetSetting()
		{
			BuildingOutLineSettingInfo buildingOutLineSettingInfo = new BuildingOutLineSettingInfo();
			string workingLocation = Product.WorkingLocation;
			string text = Path.Combine(workingLocation, "BuildingOutLineSetting.xml");
			if (!File.Exists(text))
			{
				buildingOutLineSettingInfo.LinePatternName = "实线";
				buildingOutLineSettingInfo.LineWidth = 3;
				return buildingOutLineSettingInfo;
			}
			YJKCodeBase.XmlUtility.XmlHelper xmlHelper = new YJKCodeBase.XmlUtility.XmlHelper(text, "Root");
			xmlHelper.SelectNode("Root\\Datas");
			buildingOutLineSettingInfo.LinePatternName = xmlHelper.GetValue("LinePatternName");
			buildingOutLineSettingInfo.LineWidth = Convert.ToInt32(xmlHelper.GetValue("LineWidth"));
			return buildingOutLineSettingInfo;
		}
	}
}
